//hui.getViewById('/html/personcenter.html').reload();
var shares=null;
//获取token
//var token = localStorage.getItem("token");	
//if(!token){
//	hui.open('/html/login.html?name=personcenter',{},true);
//	
//}
hui.ajax({
	    type : 'POST',
	    url : globleobj['domain']+'/residents/issign',
	    data : {'token':token},
	    success : function(msg){
	    	var data = JSON.parse(msg);
	    	hui('.hui-icons-right').hide();
	    	if(data.rc == 1){ 
	    		hui('.hui-icons-right').show();
	    	}
	    },
	    error : function(e){
	        console.log(JSON.stringify(e));
	        hui.iconToast('读取消息失败', 'warn');
	    } 
});

function getuserinfo(){
	hui.ajax({
	    type : 'POST',
	    url : globleobj['domain']+'/residents/getuserinfo',
	    data : {'token':token},
	    beforeSend : function(){hui.loading();},
	    complete   : function(){hui.closeLoading();},
	    success : function(msg){
	    	console.log('getuserinfo:'+msg)
	    	var data = JSON.parse(msg)
	    	if(data.rc != 0){
	    		hui.toast(data.msg);
	    		return false; 
	    	}
	    	localStorage.setItem("user",JSON.stringify(data.user));
//	    	console.log(localStorage.getItem("user"))
	    	hui(".personName").html(data.user.realname);
	    	hui(".personPhone").html(data.user.phone);
	    	
	    },
	    error : function(e){
	        console.log(JSON.stringify(e));
	        hui.iconToast('读取消息失败', 'warn');
	    } 
	}); 
}

function goLogin(){
	localStorage.removeItem("token");
	localStorage.removeItem("Latitude");
	localStorage.removeItem("Longitude"); 
	localStorage.removeItem("getcity"); 
//	localStorage.setItem("thatQuit",false);
//	console.log(hui.allViews().length);
//	for	(var i = 0; i < hui.allViews().length; i++){
//		hui.close(hui.allViews()[i].id)
//		console.log(JSON.stringify(hui.allViews()[i].id));
//	}
	
	hui.open('/html/login.html?name=personcenter',{},true);
	console.log(JSON.stringify(hui.getCView()))
	//关闭了不需要的页面 getCView()为获取当前页面
//	hui.close(hui.getCView().id)
}
hui.ready(function(){
	getuserinfo();
	//跳转社区
	hui('#nav-news').click(function(){
	    hui.open('/html/community.html',{},true);
	});
	//跳转健康
	hui('#nav-home').click(function(){
	    hui.open('/html/homepage.html',{},true);
	});
	//跳转应用
	hui('#nav-forum').click(function(){
	    hui.open('/html/application.html',{},true);
	});
	//跳转修改
	hui('#personInfo').click(function(){
		hui.ajax({
			    type : 'POST',
			    url : globleobj['domain']+'/residents/issign',
			    data : {'token':token},
//			    beforeSend : function(){hui.loading();},
//			    complete   : function(){hui.closeLoading();},
			    success : function(msg){
			    	var data = JSON.parse(msg);
			    	console.log(data);
			    	if(data.rc == 1){ 
			    		hui('.hui-icons-right').hide();
			    		hui.open('/html/personcenter/personalInformation.html',{},true);
			    	}
			    },
			    error : function(e){
			        console.log(JSON.stringify(e));
			        hui.iconToast('读取消息失败', 'warn');
			    } 
		});
	});
	//跳转反馈
	hui('#feedback').click(function(){
	    hui.open('/html/personcenter/feedback.html',{},true);
	});
});